<?php
namespace app\common\model;

use think\facade\Db;
use think\Model;
class Courseware extends Model
{
    //自动生成写入时间
    protected $autoWriteTimestamp = true;

    public function courseware($data){

        if(empty($data['subject_id'])){
            return Db::table('courseware')
                ->alias('c')
                ->join('subject s','c.subject_id = s.id')
                ->field('c.*,s.name as subject_name')
                ->paginate($data);
        }else{
            return Db::table('courseware')
                ->alias('c')
                ->join('subject s','c.subject_id = s.id')
                ->field('c.*,s.name as subject_name')
                ->where(['c.subject_id'=>$data['subject_id']])
                ->paginate($data);
        }
    }
}